import  os
from config.conf import BASE_PATH,CONFIG_PATH

dir_list=["cases","config","data","log","report"]
class Project():
    def __init__(self,project_name):
        self.project_name=project_name
        self.project_path=os.path.join(BASE_PATH,"project",project_name)
        self.__check_file()

    def __check_file(self):
        if os.path.exists(self.project_path):
            quit("项目已存在")

    def __create_project_dir(self):
        os.mkdir(self.project_path)

    def __create_child_dir(self):
        for dir in dir_list:
            #拼装子目录的路径
            dir_path=os.path.join(self.project_path,dir)
            os.mkdir(dir_path)

    def __create_run(self):
        read_run = open(os.path.join(CONFIG_PATH,"run_template"),"r")
        write_run=open(os.path.join(self.project_path,"run.py"),"w")
        write_run.write(read_run.read())
        read_run.close()
        write_run.close()

    def __create_conf(self):
        read_run = open(os.path.join(CONFIG_PATH, "conf_template"), "r")
        write_run = open(os.path.join(self.project_path, "config","conf.py"), "w")
        write_run.write(read_run.read())
        read_run.close()
        write_run.close()

    def main(self):
        print("main")
        self.__create_project_dir()
        self.__create_child_dir()
        self.__create_run()
        self.__create_conf()







